﻿<%@ Page Title="调拨方案设置" Language="C#" MasterPageFile="~/master/m.master" %>

<script runat="server"></script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<link href="../assets/css/shelf/base.css" rel="stylesheet">
<link href="../assets/css/enterpriseLayout/subCategoryWidthSatisfy.css" rel="stylesheet" />
<link href="../assets/css/plugins/iCheck/customsmall.css" rel="stylesheet" />
<link href="../assets/css/plugins/jQuery-DataTables/css/dataTables.bootstrap4.min.css" rel="stylesheet" />
<link href="../assets/js/plugins/jQuery-DataTables/extensions/Select/css/select.bootstrap.min.css" rel="stylesheet" />
<link href="../assets/js/plugins/jQuery-DataTables/extensions/Buttons/css/buttons.bootstrap.min.css" rel="stylesheet" />
<link href="../assets/css/plugins/bootstrap-select/bootstrap-select.min.css" rel="stylesheet" />
<link href="../assets/css/distribute/Distribute.css" rel="stylesheet" />
<style>
.left-part {border-right: 1px solid #dfdfdd; text-align: center;}
.loadTable thead tr{height: 10px;}
.left-part{width:150px;}
.right-part{width: calc(100% - 150px);}
.prjItem{ text-align: center;}
.loadTable{ width: 100%;}
.p-title{ text-align: left;background-color: #f3f3f4;line-height: 18px;}
.form-horizontal{border-bottom: 1px solid #e5e5e5;}
.form-horizontal .form-group label{ /*width: 65px;*/ padding-left: 0px; padding-right: 0px; text-align: right;}
.form-horizontal .form-group .inlineinput {border-bottom: 1px solid #dbdbdb;border-top:0px;  border-left:0px;  border-right:0px; width: 100% }
.form-horizontal .checkBoxTime{margin-left: 10px;position: relative;top: 2px;}
.form-horizontal .timeTitle{line-height: 22px;display: inline-block;position: relative;border-right: 1px solid #dfdfdd;border-bottom: 1px solid #dfdfdd; border-top:  1px solid #dfdfdd; padding-left: 10px;width: 56px;cursor: pointer;float: left;}
.form-horizontal .bl{border-left: 1px solid #dfdfdd;}
.form-horizontal .timeTitle .icon{font-size: 11px;position: absolute;right: 1px;bottom: 1px;display: none;color: #fff;}
.form-horizontal .timeTitle.check{background: linear-gradient(135deg, #fff 74%,#00a0e5 78%,#00a0e5 100%);}
.form-horizontal .timeTitle.check .icon{display: block;}
.tips {line-height: normal;color: #bc7b21;background: #fffdcd;border-bottom: 1px solid #e5e5e5; padding-top: 2px; padding-bottom:2px;}
/*.form-horizontal .form-group textarea { width: calc(100% - 70px);}*/
.form-group {padding: 0px 1px 0px 4px;margin: 0;}
.right-part .part2 .form-control {height: 22px;}
.mycheckbox{ margin-top: 2px !important;}
.panel-heading .checkbox-inline{ padding-top: 2px;}
.panel-heading .control-label{ padding-top: 2px;}
.part2 .control-label{ width: 65px !important;}
.part1{ width: 100%;}
.part1 .control-label{ width: 65px !important;}
.part1 .form-group{ margin-left: 0px; margin-right: 0px;}
.btn-default{ background-color: #ffffff;}
.panel-heading {padding: 2px 2px;}
.table>thead>tr>th {padding: 0px;}
.table > tbody > tr > td{ padding: 0px;}
/*#tbLeft_wrapper .dataTables_scroll{ min-height: 234px;}
#tbLeft_wrapper .dataTables_scrollBody{ max-height: 210px;}
#tbRight_wrapper .dataTables_scroll{ min-height: 234px;}
#tbRight_wrapper .dataTables_scrollBody{ max-height: 210px; }*/
.checkbox-inline, .radio-inline{ padding-left: 4px;}
.shijian{ padding-left: 0px !important;}
.backselect{ color: #333;background-color: #fff;border-color: #ccc; padding: 2px;}
.fenbu ul li a{ border-top: 1px solid #dfdfdd; margin: 0px; padding-left: 5px; padding-right: 5px; text-align: center !important;}
.fenbudiv{ padding-left: 0px !important;}
.daixuan .selectAll,.yixuan .selectAll{ padding-top: 0px; padding-bottom: 0px;}
.daixuan .inverse,.yixuan .inverse{ padding-top: 0px; padding-bottom: 0px;}
.fenbudiv ul li.disabled{background-color: #d6d5cf;}
.part1{ display: inline-block;}
.part2{ display: inline-block; padding-left: 0px; padding-right: 0px;}
.lblMaterialID{ padding-left: 0px; padding-right: 0px;}
.parttip{ margin-left: 0px !important; margin-right: 0px !important;padding-left: 0px;}
.left-part td.ProjectName{ line-height: 30px; cursor: pointer;}
.left-part td.ProjectName span{ cursor: pointer; float: right; width: 15px;margin-top: 8px;color: #f8ac59;}
.part1 .checkbox input[type=checkbox], .part1 .checkbox-inline input[type=checkbox] {margin-left: -14px;}
.part1 .col-sm-12, .part1 .col-sm-3, .part1 .col-sm-5, .part1 .col-sm-7, .part1 .col-sm-8, .part1 .col-sm-9 {padding-left: 10px;}
.part2 .control-label {padding-top: 3px !important;margin-bottom: 3px !important;}
ul.tabs {margin: 0;padding: 0;float: left;list-style: none;height: 23px;border-bottom: 1px solid #dfdfdd;width: 100%;}
ul.tabs li {float: left;margin: 0;cursor: pointer;padding: 0px 21px;height: 22px;line-height: 22px;border-top: 1px solid #dfdfdd;border-left: 1px solid #dfdfdd;border-bottom: 1px solid #dfdfdd;background-color: #ddd;color: #000;overflow: hidden;position: relative;}
ul.tabs li:hover {background-color: #ccc;color: #dfdfdd;}
ul.tabs li.active {background-color: #fff;color: #000;border-bottom: 1px solid #fff;display: block;}
.tab_container {border: 1px solid #dfdfdd;border-top: none;clear: both;float: left;width: 100%;background: #fff;overflow: auto;}
.tab_content {padding:2px 0px 0px 0px;display: none;}
.tab_last { border-right: 1px solid #dfdfdd; }
#btnGetList {padding: 0px 12px;top: -23px;right: 2px;}
#search-materialID {min-height: 46px !important;margin-bottom: 2px;}
.addShop,.addAllShop,.removeShop,.removeAllShop {cursor: pointer;}   
.borderred {border: 2px solid red;}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="main" Runat="Server">
<div class="system-box">
	<div class="right-side">
		<div class="btns-container"></div>
		<div class="left-part">
			<div class="p-title">方案列表</div>
		    <div class="tb-body-container" id="tbc1">
				<table class="loadTable">
					<tbody class="loadList"></tbody>
				</table>
			</div>
		</div>
		<div class="right-part">
            <form class="form-horizontal" role="form">
                <div class="part1">
		            <div class="p-title  col-sm-12">方案详情</div>
	                <div class="form-group col-sm-5">
		                <label for="projectName" class="col-sm-3 control-label">方案名：</label>
		                <div class="col-sm-8" style="padding-left: 0px;">
	                        <input type="text" id="projectName" data-projectcode="" class="form-control inlineinput">
		                </div>
	                </div>
	                <div class="form-group col-sm-7">
                        <label for="projectState" class="col-sm-3 control-label">方案状态：</label>
		                <div class="col-sm-5 fangan">
			                <div class="checkbox-inline">
				                <label>
					                <input type="checkbox" id="projectState" class="mycheckbox" checked="checked"> 启用
				                </label>
			                </div>
		                </div>
	                </div>
	                <div class="form-group col-sm-5 quyu">
		                <label class="col-sm-3 control-label">调拨区域：</label>
                        <div class="col-sm-9">
			                <div class="checkbox-inline">
				                <label>
					                <input type="checkbox" id="AreaPart_dan" data-value="1"  class="mycheckbox" checked="checked">单分部
				                </label>
			                </div>
                            <div class="checkbox-inline">
				                <label>
					                <input type="checkbox" id="AreaPart_duo" data-value="2"  class="mycheckbox">多分部
				                </label>
			                </div>
                            <div class="checkbox-inline">
				                <label>
					                <input type="checkbox" id="AreaPart_zuhe" data-value="3"  class="mycheckbox">组合|
				                </label>
                                <label style="margin-left: 18px;" class="partFirst hide">
					                <input type="checkbox"  id="AreaPartFirst"  class="mycheckbox">分部优先
				                </label>
			                </div>
                        </div>
	                </div>
	                <div class="form-group col-sm-7 fenbu">
		                <label class="col-sm-3 control-label">零售分部：</label>
                        <div class="col-sm-5 fenbudiv" id="salePartSingle">
                            <select class="form-control input-w140" id="search-salePart_dan" data-style="backselect"></select>
                        </div>
                      <div class="col-sm-5 fenbudiv hide" id="salePartMultiple2">
                            <select class="form-control input-w140" id="search-salePart_duo" data-style="backselect" multiple></select>
                        </div>
                        <div class="col-sm-5 fenbudiv hide" id="salePartMultiple">
                            <select class="form-control input-w140" id="search-salePart_zuhe" data-style="backselect" multiple="multiple"></select>
                        </div>
	                </div>
                    <div class="clearfix"></div> 
	                <div class="form-group col-sm-5 zhouqi">
		                <label class="col-sm-3 control-label">执行周期：</label>
                        <div class="col-sm-9">
			                <div class="checkbox-inline">
				                <label>
					                <input type="checkbox" id="TimeEveryWeek" data-value="1" class="mycheckbox" checked="checked">每周
				                </label>
			                </div>
                            <div class="checkbox-inline">
				                <label>
					                <input type="checkbox"id="TimeSimpleWeek" data-value="2"  class="mycheckbox">单周
				                </label>
			                </div>
                            <div class="checkbox-inline">
				                <label>
					                <input type="checkbox" id="TimeDoubleWeek" data-value="3"  class="mycheckbox">双周
				                </label>
			                </div>
                        </div>
	                </div>
	                <div class="form-group col-sm-7">
		                <label class="col-sm-3 control-label">执行时间：</label>
                        <div class="col-sm-9 shijian">
                                <div class="cb" style="padding: 0 0 0 0px; overflow: hidden;display: inline-block;">
				                <input type="checkbox" class="checkBoxTime hide" value="1"  checked="checked"/><span class="timeTitle bl check">星期一<i class="fa fa-check icon"></i></span>
	                            <input type="checkbox" class="checkBoxTime hide" value="2" /><span class="timeTitle">星期二<i class="fa fa-check icon"></i></span>
	                            <input type="checkbox" class="checkBoxTime hide" value="3" /><span class="timeTitle">星期三<i class="fa fa-check icon"></i></span>
	                            <input type="checkbox" class="checkBoxTime hide" value="4" /><span class="timeTitle">星期四<i class="fa fa-check icon"></i></span>
	                            <input type="checkbox" class="checkBoxTime hide" value="5" /><span class="timeTitle">星期五<i class="fa fa-check icon"></i></span>
	                            <input type="checkbox" class="checkBoxTime hide" value="6" /><span class="timeTitle">星期六<i class="fa fa-check icon"></i></span>
	                            <input type="checkbox" class="checkBoxTime hide" value="7" /><span class="timeTitle">星期日<i class="fa fa-check icon"></i></span>
			                </div>
                        </div>
	                </div>
                </div>
                <div class="form-group col-sm-12 parttip">
                    <div class="tips">
                        <i class="fa fa-lightbulb-o"></i>执行周期：零售分部方案一般是每周执行，组合方案指定单或双周执行；分部优先指各分部内先跑数，然后再全部一起跑数。关联查询条件：根据货品范围条件显示货号
                    </div>
                </div>
                <div  class="part2 col-sm-12">
                    <div>
                         <ul class="tabs">
                          <li class="active" rel="tab1">货品范围</li>
                          <li rel="tab2" class="tab_last">货号筛选</li>
                        </ul>
                        <div style="height: 0px;float: right;">
	                        <button type="button" class="btn btn-primary" style="position: relative;" id="btnGetList">查询</button>
		                </div>
                    </div>
                    <div class="tab_container">
                      <div id="tab1" class="tab_content" style="display: block;">
                           <div class="form-group col-sm-3">
		                            <label for="search-Year" class="col-sm-3 control-label">年份：</label>
                                    <div class="col-sm-5">
                                        <select class="form-control input-w90" id="search-Year"><option value="">请选择</option></select>
                                    </div>
	                            </div>
	                            <div class="form-group col-sm-3">
		                            <label for="search-Season" class="col-sm-3 control-label">季节：</label>
                                    <div class="col-sm-5">
                                        <select class="form-control input-w90" id="search-Season"><option value="">请选择</option></select>
                                    </div>
	                            </div>
	                            <div class="form-group col-sm-3">
		                            <label for="search-gender" class="col-sm-3 control-label">性别：</label>
                                    <div class="col-sm-5">
                                        <select class="form-control input-w90" id="search-gender"><option value="">请选择</option></select>
                                    </div>
	                            </div>
	                            <div class="form-group col-sm-3">
		                            <label for="search-type" class="col-sm-3 control-label">类别：</label>
                                    <div class="col-sm-5">
                                        <select class="form-control input-w90" id="search-type"></select>
                                    </div>
	                            </div>
	                            <div class="form-group col-sm-3">
		                            <label for="search-series" class="col-sm-3 control-label">系列：</label>
                                    <div class="col-sm-5">
                                        <select class="form-control input-w90" id="search-series"></select>
                                    </div>
	                            </div>
	                            <div class="form-group col-sm-3">
		                            <label for="search-layer" class="col-sm-3 control-label">商品层：</label>
                                    <div class="col-sm-5">
                                        <select class="form-control input-w90" id="search-layer"></select>
                                    </div>
	                            </div>
	                            <div class="form-group col-sm-3">
		                            <label for="search-category" class="col-sm-3 control-label">品类：</label>
                                    <div class="col-sm-5">
                                        <select class="form-control input-w90" id="search-category"></select>
                                    </div>
	                            </div>
	                            <div class="form-group col-sm-3">
		                            <label for="search-item" class="col-sm-3 control-label">小品类：</label>
                                    <div class="col-sm-5">
                                        <select class="form-control input-w90" id="search-item"><option value="">请选择</option></select>
                                    </div>
	                            </div>
                      </div>
                      <!-- #tab1 -->
                      <div id="tab2" class="tab_content" style="display: none;">
                             <div class="form-group col-sm-12">
                                <label for="search-materialID" class="col-sm-1 control-label">货号：</label>
		                        <div class="col-sm-11 lblMaterialID">
	                                <textarea name="search-materialID" placeholder="货号,多个货号时用逗号分隔"  style="resize:none"  class="form-control" id="search-materialID" ></textarea>
		                        </div>
	                          </div>
                      </div>
                      <!-- #tab2 -->
                    </div>
                    <!-- .tab_container -->
                </div>
           
                <div class="col-xs-5 no-padding daixuan">
                    <div class="panel panel-default m-b-xxs panelLeft m-t-xs overflow-hidde">
                        <div class="panel-heading">
                            <div class="form-group">
		                        <label class="col-sm-3 control-label" style="text-align: left !important;padding-left: 15px;">待选货号</label>
                                <div class="col-sm-9 text-right" style="height: 22px;">
			                        <button type="button" class="btn btn-xs btn-primary pull-right m-xxs inverse">反选</button>
                                    <button type="button" class="btn btn-xs btn-warning pull-right m-xxs selectAll">全选</button>
                                </div>
	                        </div>
                        </div>
                        <table class="table table-bordered     text-center" id="tbLeft" style="margin-top: 0 !important; border-left: 0; border-right: 0;" width="100%"></table>
                    </div>
                </div>
                <div class="col-xs-1 text-center">
                    <div class="m-t-md addShop"><i class="fa fa-angle-right fa-3x"></i></div>
                    <div class="addAllShop"><i class="fa fa-angle-double-right fa-3x"></i></div>
                    <div class="m-t-md removeShop"><i class="fa fa-angle-left  fa-3x"></i></div>
                    <div class="removeAllShop"><i class="fa fa-angle-double-left fa-3x"></i></div>
                </div>
                <div class="col-xs-6 no-padding  yixuan">
                    <div class="panel panel-default m-b-xxs panelRight m-t-xs overflow-hidde">
                        <div class="panel-heading">
                            <div class="form-group">
		                        <label for="firstname" class="col-sm-3 control-label"  style="text-align: left !important;padding-left: 15px;">已选货号</label>
                                <div class="col-sm-9 text-right" style="height: 22px;">
                                    <button type="button" class="btn btn-xs btn-primary pull-right m-xxs inverse">反选</button>
                                    <button type="button" class="btn btn-xs btn-warning pull-right m-xxs selectAll">全选</button>
                                    <div class="checkbox-inline">
				                        <label>
					                        <input type="checkbox" class="mycheckbox" id="relatedQuery">关联查询
				                        </label>
			                        </div>
                                </div>
	                        </div>
                        </div>
                        <table class="table table-bordered  text-center" width="100%" id="tbRight" style="margin-top: 0 !important; border-left: 0; border-right: 0;"></table>
                    </div>
                </div>
            </form>
        </div>	 
	</div>
	<div class="cb"></div>
</div>
    
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="footer" Runat="Server">
<script src="../assets/js/page/tableControl.js"></script>
<script src="../assets/js/plugins/iCheck/icheck.min.js"></script>
<script src="../assets/js/plugins/iCheck/icheckAll.js"></script>
<script src="../assets/js/plugins/jQuery-DataTables/jquery.dataTables.min.js"></script>
<script src="../assets/js/plugins/jQuery-DataTables/dataTables.bootstrap.js"></script>
<script src="../assets/js/plugins/jQuery-DataTables/extensions/Select/js/dataTables.select.min.js"></script>
<script src="../assets/js/plugins/jQuery-DataTables/extensions/Buttons/js/dataTables.buttons.min.js"></script>
<script src="../assets/js/plugins/bootstrap-select/bootstrap-select.min.js"></script>
<script src="../assets/js/plugins/bootstrap-select/i18n/defaults-zh_CN.min.js"></script>
<script src="../assets/js/plugins/linq/jquery.linq.min.js"></script>

<script>
    $.expr[':'].textEquals = $.expr.createPseudo(function (arg) {
        return function (elem) {
            return $(elem).text().match("^" + arg + "$");
        };
    });

    var elemExisted = function(arr, id, name) {
        if (id == "" || name == "") {
            //有其中一个为空就返回true(为了不重复添加)
            return true;
        }
        for (var i = 0; i < arr.length; i++) {
            if (arr[i].MaterialID == id && arr[i].MaterialShortName == name) {
                return true;
            }
        }
        return false;
    };

    var objExisted = function (arr, obj) {
        if (obj.MaterialID == "" || obj.MaterialShortName == "") {
            //有其中一个为空就返回true(为了不重复添加)
            return true;
        }
        for (var i = 0; i < arr.length; i++) {
            if (arr[i].MaterialID == obj.MaterialID && arr[i].MaterialShortName == obj.MaterialShortName) {
                return true;
            }
        }
        return false;
    };

    var removeObj = function (arr, obj) {
        var length = arr.length;
        for (var i = 0; i < length; i++) {
            if (arr[i].MaterialID == obj.MaterialID && arr[i].MaterialShortName == obj.MaterialShortName) {
                if (i == 0) {
                    arr.shift(); //删除并返回数组的第一个元素
                    return;
                }
                else if (i == length - 1) {
                    arr.pop();  //删除并返回数组的最后一个元素
                    return;
                }
                else {
                    arr.splice(i, 1); //删除下标为i的元素
                    return;
                }
            }
        }
    };

    var formatGroup = function (id, name) {
        return 'group_' + id.replace("#N/A", "_") + "_" + name;
    };

    var checkInput = function (txt) {
        if (txt == "") {
            console.log("货号为空");
            return false;
        }
        var strExp = /^[A-Za-z0-9]+$/;
        //先处理特殊的
        var mArrr = txt.replace("#N/A", "").split(",");
        for (var i = 0; i < mArrr.length; i++) {
            //验证连续逗号
            if (mArrr[i] == "") {
                console.log("有多余的逗号");
                return false;
            }
            //验证货号格式
            if (!strExp.test(mArrr[i])) {
                console.log("第"+(i+1)+"个货号格式不正确"); 
                return false;
            }
        }
        return true;
    };


    var tbLeft, tbRight;
    var modelList = [];
    $(document).ready(function(){
        var ModuleID = Y.getUrlParam("ModuleID");
        //获取按钮
        commonUtil.loadBtnList(ModuleID, function () { });

        //类别
        commonUtil.bindGetDropDownList(['#search-type'], 1,function() {
            $('#search-type option').eq(0).prop("selected", true);
        });
        //系列
        commonUtil.bindGetDropDownList(['#search-series'], 2,function() {
            $('#search-series option').eq(0).prop("selected", true);
        });
        //商品层
        commonUtil.bindGetDropDownList(['#search-layer'], 3,function() {
            $('#search-layer option').eq(0).prop("selected", true);
        });
        //性别
        commonUtil.getSexList(['#search-gender']);
        //品类
        commonUtil.bindGetDropDownList(['#search-category'], 4,function() {
            $('#search-category option').eq(0).prop("selected", true);
            $("#search-category").trigger("change");
        });
        //小品类
        $(document).on("change", "#search-category", function () {
            $("#search-subCategory").html('<option value="">请选择</option>');
            if ($(this).val() == "")
                return;
            $('#search-item').empty();
            $("#search-item").html('<option value="">请选择</option>');
            commonUtil.bindDropDownItem(['#search-item'], $(this).val()); //小品类
        });
        //年份
        commonUtil.bindDwGlobalVariables({ dictValue: '年份' }, ['#search-Year']);
        //季节
        commonUtil.bindSeasonList({ dictValue: '季节' }, ['#search-Season']);

        //星期
        $('.form-horizontal .timeTitle').click(function () {
            $('.form-horizontal .timeTitle').removeClass('check');
            $(this).addClass('check');

            $('.checkBoxTime').prop('checked', false);
            $('.checkBoxTime').eq($('.form-horizontal .timeTitle').index(this)).click();
        });


        //设置零售分部的disabled（只有在组合的时候可以改）
        var setOperationAreaList = function (allotArea, operationAreaList) {
            Y.API2('MvAllotProject', 'GetUsedOperationArea', { AllotArea: allotArea }, function (list) {
                if (list.length > 0) {
                    console.log("setOperationAreaList=" + allotArea);
                    if (allotArea == 1) {
                        //$('#search-salePart_dan').selectpicker('val', ['xx']).selectpicker('refresh');
                        $('#search-salePart_dan').find('option').prop('disabled', false);
                        for (var j = 0; j < list.length; j++) {
                            $('#search-salePart_dan').find('option[value="' + list[j].OperationAreaID + '"]').prop('disabled', true);
                        }
                        for (var j = 0; j < operationAreaList.length; j++) {
                            $('#search-salePart_dan').find('option[value="' + operationAreaList[j] + '"]').prop('disabled', false);
                        }
                        $('#search-salePart_dan').selectpicker('refresh');
                    } else if (allotArea == 2) {
                        //$('#search-salePart_duo').selectpicker('val', ['xx']).selectpicker('refresh');
                        $('#search-salePart_duo').find('option').prop('disabled', false);
                        for (var j = 0; j < list.length; j++) {
                            $('#search-salePart_duo').find('option[value="' + list[j].OperationAreaID + '"]').prop('disabled', true);
                        }
                        for (var j = 0; j < operationAreaList.length; j++) {
                            $('#search-salePart_duo').find('option[value="' + operationAreaList[j] + '"]').prop('disabled', false);
                        }
                        $('#search-salePart_duo').selectpicker('refresh');
                    } else if (allotArea == 3) {
                        //$('#search-salePart_zuhe').selectpicker('val', ['xx']).selectpicker('refresh');
                        $('#search-salePart_zuhe').find('option').prop('disabled', false);
                        for (var j = 0; j < list.length; j++) {
                            $('#search-salePart_zuhe').find('option[value="' + list[j].OperationAreaID + '"]').prop('disabled', true);
                        }
                        for (var j = 0; j < operationAreaList.length; j++) {
                            $('#search-salePart_zuhe').find('option[value="' + operationAreaList[j] + '"]').prop('disabled', false);
                        }
                        $('#search-salePart_zuhe').selectpicker('refresh');
                    }
                }
            });
        };

        //零售分部
        commonUtil.bindBasOperationArea3(['#search-salePart_dan', '#search-salePart_duo', '#search-salePart_zuhe'], function () {
            var options = ('#search-salePart_dan option');
            var items = [];
            $(options).each(function (i) {
                items.push( $(this).val());
            });
            //单分部
            if (items.length == 1) {
                //调拨区域
                $('.quyu .mycheckbox').prop('checked', false);
                $('.quyu #AreaPart_dan').prop('checked', true);
                $('.quyu .mycheckbox').not('#AreaPart_dan').prop('disabled', true);
                //选中
                $('#search-salePart_dan').selectpicker({ 'val': items, showTick: true });
                //禁止修改
                $('#search-salePart_dan option').prop('disabled', true);
                $('#search-salePart_dan').selectpicker('refresh');
                //切换列表
                $('#search-salePart_zuhe').parents('.fenbudiv').addClass('hide');
                $('#search-salePart_duo').parents('.fenbudiv').addClass('hide');
                $('#search-salePart_dan').parents('.fenbudiv').removeClass('hide');
                //默认方案名
                $('#projectName').val($('#search-salePart_dan option').eq(0).text());

                setOperationAreaList(1, []);
            } else if (items.length > 1 && items.length < 10) {
                //调拨区域
                $('.quyu .mycheckbox').prop('checked', false);
                $('#AreaPart_zuhe').prop('disabled', true);
                $('.quyu #AreaPart_duo').prop('checked', true);
                //赋值
                $('#search-salePart_dan').selectpicker({ 'val': [''], showTick: true });
                $('#search-salePart_duo').selectpicker({ 'title': '请选择', showTick: true });
                //禁止修改
                //$('#search-salePart_duo option').prop('disabled', true);
                $('#search-salePart_dan').selectpicker('refresh');
                $('#search-salePart_duo').selectpicker('refresh');
                //切换列表
                $('#search-salePart_duo').parents('.fenbudiv').removeClass('hide');
                $('#search-salePart_zuhe').parents('.fenbudiv').addClass('hide');
                $('#search-salePart_dan').parents('.fenbudiv').addClass('hide');

                setOperationAreaList(2, []);
            }else
            {
                //调拨区域
                $('.quyu .mycheckbox').prop('checked', false);
                $('.quyu #AreaPart_zuhe').prop('checked', true);
                $('.quyu .mycheckbox').not('#AreaPart_zuhe').not('#AreaPartFirst').prop('disabled', true);
                //赋值
                $('#search-salePart_zuhe').selectpicker({ 'title': '请选择' });
                //禁止修改
                //$('#search-salePart_zuhe option').prop('disabled', true);
                //$('#search-salePart_zuhe').selectpicker('refresh');
                //切换列表
                $('#search-salePart_zuhe').parents('.fenbudiv').removeClass('hide');
                $('#search-salePart_duo').parents('.fenbudiv').addClass('hide');
                $('#search-salePart_dan').parents('.fenbudiv').addClass('hide');
                //
                $('.partFirst').removeClass('hide');

                setOperationAreaList(3, []);
            }
        });
    
        //执行周期单选效果
        $('.zhouqi .mycheckbox').click(function () {
            $('.zhouqi .mycheckbox').prop('checked',false);
            $(this).prop('checked', true);
        });

        $('#search-salePart_dan').on('changed.bs.select', function (e) {
            if ($('#projectName').attr('data-projectcode') == "") {
                $('#projectName').val($('#search-salePart_dan option:checked').text());

            }
        });

        //动态计算控件大小
        var calcContainer = function () {
            $('#tbc1').height($('.right-side').height() -
                $('.btns-container').outerHeight() -
                $('.left-part .p-title').outerHeight() -
                3);

            $('.dataTables_scroll').height($('.right-part').height() -
                $('.part1').outerHeight() -
                $('.parttip').outerHeight() -
                $('.part2').outerHeight() -
                $('.daixuan .panel-heading').outerHeight() -
                23);

            $('.dataTables_scrollBody').height($('.right-part').height() -
                $('.part1').outerHeight() -
                $('.parttip').outerHeight() -
                $('.part2').outerHeight() -
                $('.daixuan .panel-heading').outerHeight() -
                $('.dataTables_scrollHead').outerHeight() -
                23);
            //计算表格高度
            //$('#tbc1').height($('.right-side').height() - $('.conditions').outerHeight() - $('#thc1').outerHeight() - 60);

            //if($('#tbc2 tr').size() == 0)
            //	$('#tbc2').height(0);
            //else
            //	$('#tbc2').height($('.right-side').height() - $('.totalControl').outerHeight() - $('#thc2').outerHeight() - 62);
        }
    
        //加载左侧列表
        var loadLeftList = function () {

            layer.msg('玩命加载中……', { icon: 16, shade: 0.5, time: 0, maxWidth: 200 });
            Y.API2('MvAllotProject', 'GetProjectList', {
            }, function (data) {
                layer.closeAll('dialog');
                if (data.Success == false) {
                    swal(data.Message, '', 'error');
                } else {
                    var tBody = [];
                    if (!Y.checkNull(data)) {
                        data.map(function (item, i) {
                            var tempTr = {
                                trClass: i % 2 == 0 ? '' : 'footable-odd',
                                children: [
                                    { tdText: (item.ProjectCode || ''), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'hide ProjectCode' },
                                    { tdText: (item.ProjectName || ''), c: 0, r: 0, tdHtml: '<span class="glyphicon ' + (item.ProjectState == false ? "glyphicon-star-empty" : "") + '"></span>', tdId: '', tdClass: 'ProjectName' }
                                ]
                            };
                            tBody.push(tempTr);
                        });
                        tableControl.initTbody('#tbc1 .loadTable', (tBody.length > 0 ? tBody : null), 0, null);
                        $('.left-part td:textEquals("' + $('#projectName').val() + '")').parents('tr').addClass('check');
                        calcContainer();
                        return false;
                    } else {
                        $('#tbc1 .loadList').append('<tr class="noMessage">\
                                                    <td style="width:10%;"><i class="fa fa-frown-o"></i></td>\
                                                    <td style="width:80%;">无数据</td>\
                                                </tr>');
                        calcContainer();
                    }
                }
            });
        }

        var opts = {
            language: { url: "../assets/js/plugins/jQuery-DataTables/i18n/Chinese.json" },
            scrollX: true,
            searching: false,
            paging: false,
            info: false,
            ordering: false,
            lengthChange: false,
            processing: true,
            initComplete: function (settings, json) {
                //console.log("initComplete");
            },
            ajax: {
                url: '/api.ashx?c=DwGlobalVariable&a=GetOdsErpSDMatMaterial&u=',
                type: "POST",
                dataSrc: function (json) {
                    if (json.Success == false) {
                        swal(json.Message, '', 'error');
                        return [];
                    } else {
                        var datas = json.Data;
                        var newArr = [];
                        for (var i = 0; i < datas.length; i++) {
                            var id1 = datas[i].MaterialID;
                            var name1 = datas[i].MaterialShortName;
                            var id2 = (i + 1 < datas.length) ? datas[i + 1].MaterialID : "";
                            var name2 = (i + 1 < datas.length) ? datas[i + 1].MaterialShortName : "";
                            newArr.push({ MaterialID: id1, MaterialShortName: name1, MaterialID2: id2, MaterialShortName2: name2 });
                            i++;
                        }
                        //console.log("初始长度:" + datas.length + "  >>  结束长度:" + newArr.length);
                        return newArr;
                    }
                },
                data: { SeasonID: "null" }
            },
            columns: [
                {
                    title: '<input type="checkbox" name="checkAllDetail" class="checkAll" value="all"  style="visibility: hidden" />', "data": null, Sortable: false, targets: 0, orderable: false, "name": "checkbox",
                    render: function (data, type, row, meta) {
                        if (row.MaterialID == "" || row.MaterialShortName == "") {
                            return '';
                        } else {
                            return '<input type="checkbox" name="checkItemDetail" class="checkItem"   data-group="' + formatGroup(row.MaterialID, row.MaterialShortName) + '" value="' + row.MaterialID + '" />';
                        }
                    }
                },
                {
                    title: "货号", "data": "", className: "text-center", defaultContent: "", visible: true,
                    render: function (data, type, row, meta) {
                        if (row.MaterialID == "" || row.MaterialShortName == "") {
                            return '';
                        } else {
                            return '<span class="MaterialID ' + formatGroup(row.MaterialID, row.MaterialShortName) + '">' + row.MaterialID + '</span>';
                        }
                    }
                },
                {
                    title: "简称", "data": "", className: "text-center ", defaultContent: "", visible: true,
                    render: function (data, type, row, meta) {
                        if (row.MaterialID == "" || row.MaterialShortName == "") {
                            return '';
                        } else {
                            return '<span class="MaterialShortName ' + formatGroup(row.MaterialID, row.MaterialShortName) + '">' + row.MaterialShortName + '</span>';
                        }
                    }
                },
                {
                    title: '<input type="checkbox" name="checkAllDetail" class="checkAll" value="all"  style="visibility: hidden" />', "data": null, Sortable: false, targets: 0, orderable: false, "name": "checkbox",
                    render: function (data, type, row, meta) {
                        if (row.MaterialID2 == "" || row.MaterialShortName2 == "") {
                            return '';
                        } else {
                            return '<input type="checkbox" name="checkItemDetail" class="checkItem ' + (row.MaterialID2 == "" ? "hide" : "") + '"  data-group="' + formatGroup(row.MaterialID2, row.MaterialShortName2) + '" value="' + row.MaterialID2 + '" />';
                        }
                    }
                },
                {
                    title: "货号", "data": "", className: "text-center", defaultContent: "", visible: true,
                    render: function (data, type, row, meta) {
                        if (row.MaterialID2 == "" || row.MaterialShortName2 == "") {
                            return '';
                        } else {
                            return '<span class="MaterialID ' + formatGroup(row.MaterialID2, row.MaterialShortName2) + '">' + row.MaterialID2 + '</span>';
                        }
                    }
                },
                {
                    title: "简称", "data": "", className: "text-center", defaultContent: "", visible: true,
                    render: function (data, type, row, meta) {
                        if (row.MaterialID2 == "" || row.MaterialShortName2 == "") {
                            return '';
                        } else {
                            return '<span class="MaterialShortName ' + formatGroup(row.MaterialID2, row.MaterialShortName2) + '">' + row.MaterialShortName2 + '</span>';
                        }
                    }
                }
            ]
        }
        tbLeft = $('#tbLeft').DataTable(opts);

        var opts2 = {
            language: { url: "../assets/js/plugins/jQuery-DataTables/i18n/Chinese.json" },
            scrollX: true,
            searching: false,
            paging: false,
            info: false,
            ordering: false,
            lengthChange: false,
            processing: true,
            initComplete: function (settings, json) {
                //$(".right-side #tbRight").icheckAll({
                //    checkObj: ".checkItem",//表格下面的选择控件对象 选择器
                //    checkAllObj: "#checkAll",//全选 选择器
                //    clickoutBoxCheck: false, //点击行 不选中
                //    checkboxMargin: "5px 0 0 0 "//上右下左
                //});
            },
            columns: [
                {
                    title: '<input type="checkbox" name="checkAllDetail" class="checkAll" value="all"  style="visibility: hidden" />', "data": null, Sortable: false, targets: 0, orderable: false, "name": "checkbox",
                    render: function (data, type, row, meta) {
                        return '<input type="checkbox" name="checkItemDetail" class="checkItem"  data-group="group_' + row.MaterialID.replace("#N/A", "_") + "_" + row.MaterialShortName + '" value="' + row.MaterialID + '" />';
                    }
                },
                {
                    title: "货号", "data": "", className: "text-center", defaultContent: "", visible: true,
                    render: function (data, type, row, meta) {
                        return '<span class="MaterialID group_' + row.MaterialID.replace("#N/A", "_") + "_" + row.MaterialShortName + '">' + row.MaterialID + '</span>';
                    }
                },
                {
                    title: "简称", "data": "", className: "text-center ", defaultContent: "", visible: true,
                    render: function (data, type, row, meta) {
                        return '<span class="MaterialShortName group_' + row.MaterialID.replace("#N/A", "_") + "_" + row.MaterialShortName + '">' + row.MaterialShortName + '</span>';
                    }
                },
                {
                    title: '<input type="checkbox" name="checkAllDetail" class="checkAll" value="all" style="visibility: hidden" />', "data": null, Sortable: false, targets: 0, orderable: false, "name": "checkbox",
                    render: function (data, type, row, meta) {
                        return '<input type="checkbox" name="checkItemDetail" class="checkItem ' + (row.MaterialID2 == "" ? "hide" : "") + '"  data-group="group_' + row.MaterialID2.replace("#N/A", "_") + "_" + row.MaterialShortName2 + '" value="' + row.MaterialID2 + '" />';
                    }
                },
                {
                    title: "货号", "data": "", className: "text-center", defaultContent: "", visible: true,
                    render: function (data, type, row, meta) {
                        return '<span class="MaterialID group_' + row.MaterialID2.replace("#N/A", "_") + "_" + row.MaterialShortName2 + '">' + row.MaterialID2 + '</span>';
                    }
                },
                {
                    title: "简称", "data": "", className: "text-center", defaultContent: "", visible: true,
                    render: function (data, type, row, meta) {
                        return '<span class="MaterialShortName group_' + row.MaterialID2.replace("#N/A", "_") + "_" + row.MaterialShortName2 + '">' + row.MaterialShortName2 + '</span>';
                    }
                }
            ]
        }
        tbRight = $('#tbRight').DataTable(opts2);

        //填充右边表格
        var fillTbRight = function (list) {
            list.sort(function (x, y) {
                return x.MaterialShortName.localeCompare(y.MaterialShortName);
            });
            tbRight.clear();
            for (var i = 0; i < list.length; i++) {
                var code = list[i].MaterialID;
                var name = list[i].MaterialShortName;
                var code2 = (i + 1 < list.length) ? list[i + 1].MaterialID : "";
                var name2 = (i + 1 < list.length) ? list[i + 1].MaterialShortName : "";
                tbRight.row.add({ 'MaterialID': code, 'MaterialShortName': name, 'MaterialID2': code2, 'MaterialShortName2': name2 });
                i++;
            }
            tbRight.draw();
        };

        //处理全选反选
        $('.daixuan .selectAll').on("click", function (event) {
            var selectArr = $('#tbLeft .checkItem');
            selectArr.each(function() {
                $(this).prop("checked", true);
            });
        });
        $('.daixuan .inverse').on("click", function (event) {
            var selectArr = $('#tbLeft .checkItem');
            selectArr.each(function () {
                var state = $(this).prop('checked');
                $(this).prop('checked', !state);
            });
        });
        $('.yixuan .selectAll').on("click", function (event) {
            var selectArr = $('#tbRight .checkItem');
            selectArr.each(function () {
                $(this).prop("checked", true);
            });
        });
        $('.yixuan .inverse').on("click", function (event) {
            var selectArr = $('#tbRight .checkItem');
            selectArr.each(function () {
                var state = $(this).prop('checked');
                $(this).prop('checked', !state);
            });
        });

        //添加 选中
        $(".addShop").on("click", function (event) {
            var e = window.event || event;
            if (tbLeft && tbLeft.data().length > 0) {
                var selectArr = $('#tbLeft .checkItem:checked');
                var jqtbLeft = $(tbLeft.table().container());
                for (var i = 0; i < selectArr.length; i++) {
                    var checkbox = selectArr[i];
                    var group = $(checkbox).attr('data-group');
                    var code = jqtbLeft.find('span.MaterialID.' + group).text();
                    var name = jqtbLeft.find('span.MaterialShortName.' + group).text();

                    var code2 = "";
                    var name2 = "";

                    if (i + 1 <= selectArr.length) {
                        var checkbox2 = selectArr[i + 1];
                        var group2 = $(checkbox2).attr('data-group');
                        code2 = jqtbLeft.find('span.MaterialID.' + group2).text();
                        name2 = jqtbLeft.find('span.MaterialShortName.' + group2).text();
                        i++;
                    }

                    if (!elemExisted(modelList, code, name)) {
                        modelList.push({ 'MaterialID': code, 'MaterialShortName': name });
                    }

                    if (!elemExisted(modelList, code2, name2)) {
                        modelList.push({ 'MaterialID': code2, 'MaterialShortName': name2 });
                    }
                }
                fillTbRight(modelList);
            }
        });
        //添加 全部
        $(".addAllShop").on("click", function () {
            var e = window.event || event;
            var jqtbLeft = $(tbLeft.table().container());
            if (tbLeft && tbLeft.data().length > 0) {
                var selectArr = $('#tbLeft .checkItem');
                for (var i = 0; i < selectArr.length; i++) {
                    var checkbox = selectArr[i];
                    var group = $(checkbox).attr('data-group');
                    var code = jqtbLeft.find('span.MaterialID.' + group).text();
                    var name = jqtbLeft.find('span.MaterialShortName.' + group).text();

                    var code2 = "";
                    var name2 = "";

                    if (i + 1 <= selectArr.length) {
                        var checkbox2 = selectArr[i + 1];
                        var group2 = $(checkbox2).attr('data-group');
                        code2 = jqtbLeft.find('span.MaterialID.' + group2).text();
                        name2 = jqtbLeft.find('span.MaterialShortName.' + group2).text();
                        i++;
                    }

                    if (!elemExisted(modelList, code, name)) {
                        modelList.push({ 'MaterialID': code, 'MaterialShortName': name });
                    }

                    if (!elemExisted(modelList, code2, name2)) {
                        modelList.push({ 'MaterialID': code2, 'MaterialShortName': name2 });
                    }
                }
                fillTbRight(modelList);
            }
        });
        //删除 选中
        $(".removeShop").on("click", function (event) {
            var e = window.event || event;
            var jqtbRight = $(tbRight.table().container());
            var selectArr = $('#tbRight .checkItem:checked');
            if (selectArr.length > 0) {

                for (var i = 0; i < selectArr.length; i++) {
                    var checkbox = selectArr[i];
                    var group = $(checkbox).attr('data-group');
                    var code = jqtbRight.find('span.MaterialID.' + group).text();
                    var name = jqtbRight.find('span.MaterialShortName.' + group).text();

                    if (elemExisted(modelList, code, name)) {
                        removeObj(modelList, { 'MaterialID': code, 'MaterialShortName': name });
                    }
                }

                fillTbRight(modelList);
            }
        });
        //删除 全部
        $(".removeAllShop").on("click", function () {
            var e = window.event || event;
            var jqtbRight = $(tbRight.table().container());
            var selectArr = $('#tbRight .checkItem');
            if (selectArr.length > 0) {

                for (var i = 0; i < selectArr.length; i++) {
                    var checkbox = selectArr[i];
                    var group = $(checkbox).attr('data-group');
                    var code = jqtbRight.find('span.MaterialID.' + group).text();
                    var name = jqtbRight.find('span.MaterialShortName.' + group).text();

                    if (elemExisted(modelList, code, name)) {
                        removeObj(modelList, { 'MaterialID': code, 'MaterialShortName': name });
                    }
                }

                fillTbRight(modelList);
            }
        });



        //暂时无用
        var textareaResize = function (source, dest) {
            var resizeInt = null;

            var resizeEvent = function () {
                dest.outerWidth(source.outerWidth());
                dest.outerHeight(source.outerHeight());
            };

            source.on("mousedown", function (e) {
                resizeInt = setInterval(resizeEvent, 1000 / 15);
            });

            $(window).on("mouseup", function (e) {
                if (resizeInt !== null) {
                    clearInterval(resizeInt);
                }
                resizeEvent();
            });
        };

        //查询列表
        $('#btnGetList').on("click", function (event) {
            var model = {
                YearNo: $('#search-Year').val(),
                SeasonID: $('#search-Season').val(),
                SexID: $('#search-gender').val(),
                KindID: $('#search-type').val(),
                SeriesID: $('#search-series').val(),
                MaterialProperty:  $('#search-layer').val(),
                ModelID: $('#search-category').val(),
                ItemID: $('#search-item').val()
            };

            if ($("ul.tabs li[rel^='tab2']").hasClass('active')) {
                var materialIds = $('#search-materialID').val();
                if (materialIds == "") {
                    swal({ title: "请输入货号", text: "", type: "error" }, function () { setTimeout(function () { $('#search-materialID').focus(); }, 50); });
                    return false;
                }

                if (checkInput(materialIds)) {
                    model = {
                        MaterialIDs: materialIds
                    }
                } else {
                    swal({ title: "输入货号格式不正确", text: "", type: "error" },function () { setTimeout(function () { $('#search-materialID').focus(); }, 50); });
                    return false;
                }
            } 


            tbLeft.clear();
            tbLeft.settings()[0].ajax.data = model;
            tbLeft.ajax.reload(function () {
                //重新计算列宽
                tbLeft.columns.adjust().draw();
                if ($("#relatedQuery").prop('checked')) {
                    tbRight.clear().draw();
                    var jqtbLeft = $(tbLeft.table().container());
                    var tModelList = [];
                    for (var i = 0; i < modelList.length; i++) {
                        var o = modelList[i];
                        var group = 'group_' + o.MaterialID.replace("#N/A", "_") + "_" + o.MaterialShortName;
                        var code = jqtbLeft.find('span.MaterialID.' + group + ':textEquals("' + o.MaterialID + '")').text();
                        var name = jqtbLeft.find('span.MaterialShortName.' + group + ':textEquals("' + o.MaterialShortName + '")').text();

                        if (code.length > 0 && name.length > 0) {
                            tModelList.push({ 'MaterialID': code, 'MaterialShortName': name });
                        }
                    }
                    if (tModelList.length) {
                        fillTbRight(tModelList);
                    }
                }
            },false);
        });

        //保存方案
        $('.btns-container').on('click', '#btn-save', function () {
            var projectName = $('#projectName').val();
            if (projectName == "") {
                swal("方案名不能为空", '', 'error');
                return false;
            }
            var projectCode = $('#projectName').attr('data-projectcode');
            var allotArea = $('.quyu .mycheckbox:checked').not('#AreaPartFirst').attr('data-value');
            if (allotArea != "1" && allotArea != "2" && allotArea != "3") {
                swal("调拨区域数据错误，请刷新页面重试", '', 'error');
                return false;
            }

            var projectState = $('#projectState').prop('checked');
            var execCycle = $('.zhouqi .mycheckbox:checked').attr('data-value');
            if (execCycle != "1" && execCycle != "2" && execCycle != "3") {
                swal("执行周期数据错误，请刷新页面重试", '', 'error');
                return false;
            }
            var execWeek = $(".checkBoxTime:checked").val();
            if (execWeek == "") {
                swal("执行时间不能为空", '', 'error');
                return false;
            }

            var priorityOperationArea = $('#AreaPartFirst').prop('checked') ? 1 : 0;
            //两个零售分部，取决于调拨区域
            var operationAreaList = [];
            if (allotArea == 1) {
                $('#search-salePart_dan option:disabled').prop('disabled', false);
                var temp = $('#search-salePart_dan').val();
                if (temp == null || temp == "") {
                    swal("请选择零售分部", '', 'error');
                    return false;
                }
                operationAreaList.push(temp);
            } else if (allotArea == 2) {
                $('#search-salePart_duo option:disabled').prop('disabled', false);
                operationAreaList = $('#search-salePart_duo').val();
                if (operationAreaList == null || operationAreaList == "" || operationAreaList.length < 2) {
                    swal("调拨区域为[多分部]时,\n必须选择2个或者2个以上的零售分部", '', 'error');
                    return false;
                }
            } else if (allotArea == 3) {
                $('#search-salePart_zuhe option:disabled').prop('disabled', false);
                operationAreaList = $('#search-salePart_zuhe').val();
                if (operationAreaList == null || operationAreaList == "" || operationAreaList.length < 2) {
                    swal("调拨区域为[组合]时,\n必须选择2个或者2个以上的零售分部", '', 'error');
                    return false;
                }
            }

            var materialList = [];
            for (var i = 0; i < modelList.length; i++) {
                materialList.push({ "MaterialID": modelList[i].MaterialID });
            }
            if (materialList.length == 0) {
                swal("请选择货号", '', 'error');
                return false;
            }

            Y.API2('MvAllotProject', 'SaveProject', {
                ProjectName: projectName,
                ProjectCode: projectCode,
                AllotArea: allotArea,
                ProjectState: projectState,
                ExecCycle: execCycle,
                ExecWeek: execWeek,
                PriorityOperationArea: priorityOperationArea,
                MaterialList: materialList,
                OperationAreaList: operationAreaList
            }, function (data) {
                if (data.Success == false) {
                    swal(data.Message, '', 'error');
                } else {
                    swal('保存成功', '', 'success');
                    setOperationAreaList(allotArea, operationAreaList);
                    loadLeftList();
                }
            });
        });

        //新增
        $('.btns-container').on('click', '#addBtn', function () {
            $('.left-part .loadTable tr').removeClass('check');

            $('#projectName').val("");
            $('#projectName').attr('data-projectcode', "");
            $('#projectState').prop('checked', true);

            $('#TimeEveryWeek').click();
            $('#search-materialID').val("");

            $('.form-horizontal .timeTitle').removeClass('check');
            $('.form-horizontal .timeTitle').eq(0).click();



            var len = $('#search-salePart_dan option').length;
            $('.quyu .mycheckbox').prop('disabled', false);
            if (len == 1) {
                $('#AreaPart_dan').click();
                $('.quyu .mycheckbox').not($('#AreaPart_dan')).prop('disabled', true);
                $('#search-salePart_dan').selectpicker({ 'val': [''], showTick: true });
                $('#search-salePart_dan').selectpicker({ 'title': '请选择', showTick: true });
            } else if (len > 1 && len < 10) {
                $('#AreaPart_duo').click();
                $('.quyu .mycheckbox').not($('#AreaPart_duo')).not($('#AreaPart_dan')).prop('disabled', true);
                $('#search-salePart_duo').selectpicker({ 'val': [''], showTick: true });
                $('#search-salePart_duo').selectpicker({ 'title': '请选择', showTick: true });
            } else if (len == 10) {
                $('#AreaPart_zuhe').click();
                $('.quyu .mycheckbox').not($('#AreaPart_zuhe')).not($('#AreaPartFirst')).prop('disabled', true);
                $('#search-salePart_zuhe').selectpicker({ 'val': [''], showTick: true });
                $('#search-salePart_zuhe').selectpicker({ 'title': '请选择', showTick: true });
            }

            //if ($('#AreaPart_zuhe').prop('checked')) {
            //    $('.quyu .mycheckbox').attr('disabled', false);
            //    $('.quyu #AreaPart_zuhe').click();
            //    $('.quyu .mycheckbox').not('.quyu #AreaPart_zuhe').not('#AreaPartFirst').attr('disabled', true);

            //    $('#search-salePart_zuhe').parents('.fenbudiv').removeClass('hide');
            //    $('#search-salePart_dan').parents('.fenbudiv').addClass('hide');
            //    $('#search-salePart_duo').parents('.fenbudiv').addClass('hide');

            //    $('#search-salePart_zuhe').selectpicker('val', ['xx']).selectpicker('refresh');
            //} else if ($('#AreaPart_duo').prop('checked')) {
            //    $('#search-salePart_duo').selectpicker({ 'val': [''], showTick: true });
            //    $('#search-salePart_duo').selectpicker({ 'title': '请选择', showTick: true });
            //} else if ($('#AreaPart_dan').prop('checked')) {
            //    $('#search-salePart_dan').selectpicker({ 'val': [''], showTick: true });
            //    $('#search-salePart_dan').selectpicker({ 'title': '请选择', showTick: true });
            //}

            ////默认方案名
            //if ($('#AreaPart_dan').prop('checked')) {
            //   // $('#projectName').val($('#search-salePart_dan option').eq(0).text());
            //} else {
            //    $('#projectName').val("");
            //}

            tbRight.clear().draw();
            tbLeft.clear().draw();
            modelList = [];
        });

        //关联查询
        $("#relatedQuery").on("click", function () {
            if ($(this).prop('checked')) {
                //console.log("checked");
            } else {
                fillTbRight(modelList);
            }
        });

        //选中行（左侧）
        $('.left-part').on('click', '.ProjectName', function () {
            //设置样式
            $(this).parents('.loadList').find('tr').removeClass('check');
            $(this).parents('tr').addClass('check');
            //清表
            tbLeft.clear().draw();
            tbRight.clear().draw();
            //获取详细信息
            Y.API2('MvAllotProject', 'GetProject', {
                ProjectCode: $(this).parents('tr').find('.ProjectCode').text()
            }, function (data) {
                if (data.Success == false) {
                    swal(data.Message, '', 'error');
                } else {
                    $('.quyu .mycheckbox').attr('disabled', false);

                    //绑定
                    $('#projectName').val(data.ProjectName);//名称
                    $('#projectName').attr('data-projectcode', data.ProjectCode);//编号
                    $('#projectState').prop('checked', data.ProjectState);//状态

                    $('#search-salePart_zuhe').selectpicker('val', ['']);
                    $('#search-salePart_dan').selectpicker('val', ['']);
                    $('#search-salePart_duo').selectpicker('val', ['']);
                    if (data.AllotArea == 1) //调拨区域1-分部;2-组合
                    {
                        $('#AreaPart_dan').click();
                        $('.quyu .mycheckbox').not('.quyu .mycheckbox:checked').attr('disabled', true);
                        $('#AreaPartFirst').attr('disabled', true);
                        $('#search-salePart_dan').parents('.fenbudiv').removeClass('hide');
                        $('#search-salePart_duo').parents('.fenbudiv').addClass('hide');
                        $('#search-salePart_zuhe').parents('.fenbudiv').addClass('hide');
                        $('#search-salePart_dan').selectpicker('val', data.OperationAreaList);//零售分部
                        var len = $('#search-salePart_dan option').length;
                        if (len > 1 && len < 10) {
                            $('#AreaPart_duo').attr("disabled", false);
                        }
                    } else if (data.AllotArea == 2) {
                        $('#AreaPart_duo').click();
                        $('.quyu .mycheckbox').not('.quyu .mycheckbox:checked').attr('disabled', true);
                        $('#AreaPartFirst').attr('disabled', true);
                        $('#search-salePart_dan').parents('.fenbudiv').addClass('hide');
                        $('#search-salePart_duo').parents('.fenbudiv').removeClass('hide');
                        $('#search-salePart_zuhe').parents('.fenbudiv').addClass('hide');
                        $('#search-salePart_duo').selectpicker('val', data.OperationAreaList);//零售分部
                        var len = $('#search-salePart_dan option').length;
                        if (len > 1 && len < 10) {
                            $('#AreaPart_dan').prop("disabled", false);
                        }
                    } else if (data.AllotArea == 3) {
                        $('#AreaPart_zuhe').click();
                        $('.quyu .mycheckbox').not('.quyu .mycheckbox:checked').not('#AreaPartFirst').attr('disabled', true);
                        $('#AreaPartFirst').attr('disabled', false);
                        $('#search-salePart_dan').parents('.fenbudiv').addClass('hide');
                        $('#search-salePart_duo').parents('.fenbudiv').addClass('hide');
                        $('#search-salePart_zuhe').parents('.fenbudiv').removeClass('hide');
                        $('#search-salePart_zuhe').selectpicker('val', data.OperationAreaList);//零售分部
                    }

                    

                    $('#AreaPartFirst').prop('checked', data.PriorityOperationArea == 1 ? true : false);//分部优先
                    $('.zhouqi .mycheckbox').eq(data.ExecCycle - 1).click();//周期
                    $('.form-horizontal .timeTitle').eq(data.ExecWeek - 1).click();//执行时间

                    //不管自己是什么店铺权限，看的到就可以改
                    //if ($('#search-salePart_dan option').length != 10) {
                    //    //不是组合的时候，看得到的都可以改
                    //    $('#btn-save').prop("disabled", false);
                    //}
                    //绑定零售分部的状态
                    setOperationAreaList(data.AllotArea, data.OperationAreaList);
                    //绑定商品列表
                    modelList = [];
                    var mList = data.MaterialList;
                    if (mList.length > 0) {
                        for (var l = 0; l < mList.length; l++) {
                            var code = mList[l].MaterialID;
                            var name = mList[l].MaterialShortName;
                            var code2 = (l + 1 < mList.length) ? mList[l + 1].MaterialID : "";
                            var name2 = (l + 1 < mList.length) ? mList[l + 1].MaterialShortName : "";

                            if (!elemExisted(modelList, code, name)) {
                                modelList.push({ 'MaterialID': code, 'MaterialShortName': name });
                            }

                            if (!elemExisted(modelList, code2, name2)) {
                                modelList.push({ 'MaterialID': code2, 'MaterialShortName': name2 });
                            }
                        }
                        fillTbRight(modelList);
                    }

                }
            });
        });

        //区域切换ssdsadasd
        $('.quyu .mycheckbox').click(function () {
            //全清
            //$('.quyu .mycheckbox').not("#AreaPartFirst").prop('checked', false);

            if ($(this).prop('id') == 'AreaPart_dan') {
                $('.quyu .mycheckbox').prop('checked', false);
                $(this).prop('checked', true);
                //$('.partFirst').addClass('hide');

                $('#search-salePart_zuhe').parents('.fenbudiv').addClass('hide');
                $('#search-salePart_duo').parents('.fenbudiv').addClass('hide');
                $('#search-salePart_dan').parents('.fenbudiv').removeClass('hide');

                $('#search-salePart_dan').selectpicker('val', ['xx']).selectpicker('refresh');
                setOperationAreaList(1,[]);
            }
            else if ($(this).prop('id') == 'AreaPart_duo') {
                $('.quyu .mycheckbox').prop('checked', false);
                $(this).prop('checked', true);
                //$('.partFirst').addClass('hide');

                $('#search-salePart_duo').parents('.fenbudiv').removeClass('hide');
                $('#search-salePart_zuhe').parents('.fenbudiv').addClass('hide');
                $('#search-salePart_dan').parents('.fenbudiv').addClass('hide');

                $('#search-salePart_duo').selectpicker('val', ['xx']).selectpicker('refresh');
                setOperationAreaList(2, []);
            }
            else if ($(this).prop('id') == 'AreaPart_zuhe') {
                $('.quyu .mycheckbox').prop('checked', false);
                $(this).prop('checked', true);
                $('.partFirst').removeClass('hide');

                $('#search-salePart_zuhe').parents('.fenbudiv').removeClass('hide');
                $('#search-salePart_duo').parents('.fenbudiv').addClass('hide');
                $('#search-salePart_dan').parents('.fenbudiv').addClass('hide');

                $('#search-salePart_zuhe').selectpicker('val', ['xx']).selectpicker('refresh');
                setOperationAreaList(3,[]);
            } else {
                //do not thing
            }
        });

        //Tab切换
        $("ul.tabs li").click(function () {
            $(".tab_content").hide();
            var activeTab = $(this).attr("rel");
            $("#" + activeTab).fadeIn();

            $("ul.tabs li").removeClass("active");
            $(this).addClass("active");
        });

        calcContainer();
        $(window).resize(function () {
            //重新计算容器高度
            calcContainer();
        });

        //$(".mycheckbox").iCheck({ checkboxClass: "icheckbox_square-green" });
        loadLeftList();

   
  
    });

    var fk = function () {
        $('.fenbu .fenbudiv').removeClass('hide');
    }


</script>
</asp:Content>




